import 'dart:ui';

import 'package:flutter/material.dart';

class TestPaint extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("测试画笔")),
      body: ListView(
        children: <Widget>[
          CustomPaint(
            size: Size(300, 300),
            painter: MessageCustomePaint(),
          ),
        ],
      ),
    );
  }
}

class MessageCustomePaint extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    Paint _paint = new Paint()
      ..color = Colors.lightGreen
      ..strokeCap = StrokeCap.round
      ..isAntiAlias = true
      ..strokeWidth = 5.0
      ..style = PaintingStyle.stroke;

//    // 圆形 rawCircle
//    canvas.drawCircle(
//      Offset(50.0,100.0), // 圆心
//      30.0, // 半径
//      _paint
//        ..color = Colors.greenAccent
//        ..style = PaintingStyle.stroke, // 线
//    );
//
//    // 实心圆
//    canvas.drawCircle(
//      Offset(140.0, 100.0),
//      30.0,
//      _paint
//        ..color = Colors.greenAccent
//        ..style = PaintingStyle.fill, // 填充
//    );
//
//    Rect rect1 = Rect.fromPoints(Offset(100.0, 200.0), Offset(200.0, 250.0));
//    canvas.drawOval(rect1, _paint);

    // 画90度的弧度
//    const PI = 3.1415926;
//    Rect rect2 = Rect.fromCircle(center: Offset(100.0, 100.0), radius: 50.0);
//    canvas.drawArc(rect2, 0.0, PI / 2, true, _paint);

    //用Rect构建一个边长50,中心点坐标为100,100的矩形
    Rect rect = Rect.fromLTWH(50.0, 50.0, 180, 120);
    // 画圆角矩形
    //根据上面的矩形,构建一个圆角矩形
    RRect rrect = RRect.fromRectAndRadius(rect, Radius.circular(10.0));
    canvas.drawRRect(rrect, _paint..style = PaintingStyle.fill);

    canvas.drawLine(Offset(230, 80), Offset(260, 110), _paint);
    canvas.drawLine(Offset(260, 110), Offset(230, 140), _paint);

  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return false;
  }
}
